//*********************************************************
//
//    Copyright (c) Microsoft. All rights reserved.
//    This code is licensed under the Apache License, Version 2.0.
//    THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
//    ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
//    IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
//    PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//*********************************************************

using System;
using System.ComponentModel;
using System.Workflow.ComponentModel;
using Microsoft.Research.ScientificWorkflow;

namespace TridentBasicActivities.Activities
{
    [Name("Activity for comapring equality of two strings", "String Equal", "EQ")]
    [Description("Takes two string and returns TRUE, if strings are equal. Default comparison is not case sensitive")]
    [WorkflowCategory("Condition")]
    public class CondStrEQ : CondBase
    {

        /// <summary>
        /// First input string dependency property
        /// </summary>
        public static System.Workflow.ComponentModel.DependencyProperty Input1Property =
            System.Workflow.ComponentModel.DependencyProperty.Register("Input1", typeof(string), typeof(CondStrEQ));
        [RequiredInputParam]
        [Name("Input1")]
        [Description("First string value for doing the comparison.")]
        public string Input1
        {
            get { return (string)GetValue(CondStrEQ.Input1Property); }
            set { SetValue(CondStrEQ.Input1Property, value); }
        }

        /// <summary>
        /// Second input string dependency property
        /// </summary>
        public static System.Workflow.ComponentModel.DependencyProperty Input2Property =
                   System.Workflow.ComponentModel.DependencyProperty.Register("Input2", typeof(string),
                   typeof(CondStrEQ));
        [RequiredInputParam]
        [Name("Input2")]
        [Description("Second string value for doing the comparison.")]
        public string Input2
        {
            get { return (string)GetValue(CondStrEQ.Input2Property); }
            set { SetValue(CondStrEQ.Input2Property, value); }
        }

        ///// <summary>
        ///// Ignore case dependency property, this will be true by default
        ///// </summary>
        //public static System.Workflow.ComponentModel.DependencyProperty IgnoreCaseProperty =
        //    System.Workflow.ComponentModel.DependencyProperty.Register("IgnoreCase", typeof(bool),
        //    typeof(CondStrEQ), new System.Workflow.ComponentModel.PropertyMetadata(true));
        //[RequiredInputParam]
        //[Name("Ignore case")]
        //[Description("Ignore case during comparison.")]
        //public bool IgnoreCase
        //{
        //    get { return (bool)GetValue(CondStrEQ.IgnoreCaseProperty); }
        //    set { SetValue(CondStrEQ.IgnoreCaseProperty, value); }
        //}

        /// <summary>
        /// Result dependency property, this will be true if both strings are equal 
        /// </summary>
        public static System.Workflow.ComponentModel.DependencyProperty ResultProperty =
            System.Workflow.ComponentModel.DependencyProperty.Register("Result", typeof(bool),
            typeof(CondStrEQ));
        [OutputParam]
        [Name("Result")]
        [Description("Result of the equal comparison operation.")]
        public bool Result
        {
            get { return (bool)GetValue(CondStrEQ.ResultProperty); }
            set { SetValue(CondStrEQ.ResultProperty, value); }
        }
        /// <summary>
        /// Activity execution method, compares string and sets the result dependency property
        /// </summary>
        /// <param name="executionContext"></param>
        /// <returns></returns>
        protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
        {
            StringComparison type = StringComparison.InvariantCultureIgnoreCase;
            ////If case should be considered change the comparison type
            //if (!IgnoreCase)
            //{
            //    type = StringComparison.InvariantCulture;                
            //}
            this.Result = String.Equals(this.Input1, this.Input2, type);
            return ActivityExecutionStatus.Closed;
        }
    }
}

